using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace OpenComposite.Workflow
{
	internal class MySite : ISite
	{
		public MySite(IComponent component, IContainer container, bool designMode, string name)
		{
			_component = component;
			_container = container;
			_designMode = designMode;
			_name = name;

			if ( _container is IServiceProvider ) {
				_serviceProvider = (IServiceProvider)_container;
			} else if ( _component is IServiceProvider ) {
				_serviceProvider = (IServiceProvider)_component;
			} else {
				_serviceProvider = null;
			}
		}
		private IServiceProvider _serviceProvider;
		private IComponent _component;
		private IContainer _container;
		private bool _designMode;
		private string _name;

		#region ISite Members

		public IComponent Component
		{
			get { return _component; }
		}

		public IContainer Container
		{
			get { return _container; }
		}

		public bool DesignMode
		{
			get { return _designMode; }
		}

		public string Name
		{
			get
			{
				return _name;
			}
			set
			{
				_name = value;
			}
		}

		#endregion

		#region IServiceProvider Members

		public object GetService(Type serviceType)
		{
			object svc = null;
			if ( _serviceProvider != null ) {
				svc = _serviceProvider.GetService(serviceType);
			}
			return svc;
		}

		#endregion
	}
}
